package cn.edu.hitsz.compiler.parser.table.symbol;

import cn.edu.hitsz.compiler.lexer.Token;
import cn.edu.hitsz.compiler.parser.table.NonTerminal;

/**
 * Union<Token,NonTerminal>
 * 同时也是语义分析所用栈的父类
 */
public class Symbol {
    Token token;
    NonTerminal nonTerminal;


    public Symbol(Token token, NonTerminal nonTerminal){
        this.token = token;
        this.nonTerminal = nonTerminal;
    }

    public Symbol(Token token){
        this.token = token;
        this.nonTerminal = null;
    }

    public Symbol(NonTerminal nonTerminal){
        this.token = null;
        this.nonTerminal = nonTerminal;
    }

    public boolean isToken(){
        return this.token != null;
    }
    public boolean isNonterminal(){
        return this.nonTerminal != null;
    }

    public Token getToken(){return this.token;}
    public NonTerminal getNonTerminal(){return this.nonTerminal;}
}
